<!DOCTYPE html>
<html>
<head>
    <include file="Public:header" />
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-6">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="ibox-search-box">
                    		<h3>仓库</h3>
                    	</div>
                    	<p>
                    		<button type="button" id="add" class="btn btn-white btn-sm btn-outline"><i class="fa fa-plus-square-o"></i>&nbsp;新增</button>
                    		<button type="button" id="edit" class="btn btn-white btn-sm btn-outline"><i class="fa fa-edit"></i>&nbsp;修改</button>
                    	</p>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="ibox-search-box">
                    		<h3>库存</h3>
                    	</div>
                    	<p>
                    		<button type="button" id="addSub" class="btn btn-white btn-sm btn-outline"><i class="fa fa-plus-square-o"></i>&nbsp;新增</button>
                    		<button type="button" id="editSub" class="btn btn-white btn-sm btn-outline"><i class="fa fa-edit"></i>&nbsp;修改</button>
                    	</p>
                        <div class="jqGrid_wrapper">
                            <table id="table_list2"></table>
                            <div id="pager_list2"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
$(document).ready(function () {
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllData',
    	datatype: "json",
        height: 580,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 15,
        rowList: [10, 15, 30, 50],
        colNames: ['ID', '名称', '创建时间' ],
        colModel: [ {name : 'id',index : 'id'},
                    {name : 'name',index : 'name'},
                   	{name : 'create_time',index : 'create_time',formatter: 'date',formatoptions: {srcformat:'u',newformat:'Y-m-d H:i:s'}}
                  ],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc",
        onCellSelect: function(rowid) {
           	if(rowid != null) {
           		$("#table_list2").jqGrid('setGridParam', { 
            		url : '__URL__/getStoreAllData?id=' + rowid
            	}).trigger("reloadGrid");
           	}else {
           		layer.msg("您没有选取数据！");
           	}
        }
    });
 	// 设置按钮
    $("#table_list").jqGrid('navGrid', '#pager_list', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    });
 	// 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
 	
 
    //查看库存
    $("#table_list2").jqGrid({
    	url : '__URL__/getStoreAllData',
    	datatype: "json",
        height: 580,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 15,
        rowList: [10, 15, 30, 50],
        colNames: ['ID', '名称', '库存', '更新时间' ],
        colModel: [ {name : 'id',index : 'id'},
                    {name : 'name',index : 'name'},
                    {name : 'num',index : 'num'},
                   	{name : 'update_time',index : 'update_time',formatter: 'date',formatoptions: {srcformat:'u',newformat:'Y-m-d H:i:s'}}
                  ],
        pager: "#pager_list2",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc",
    });
 	// 设置按钮
    $("#table_list2").jqGrid('navGrid', '#pager_list2', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    });
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list2').setGridWidth(width);
    });
    
  	//增
	$("#add").click(function() {
		layerDialog("新增大类",'__URL__/add',"90%","50%",true);
	})
	
    //改
    $("#edit").click(function() {
    	var id = $("#table_list").jqGrid('getGridParam','selrow');
    	if(id != null) {
    		layerDialog("修改大类",'__URL__/edit?id='+id,"90%","50%",true);
    	}else {
    		layer.msg("您没有选取数据！");
    	}
    })
    
    //增（库存）
	$("#addSub").click(function() {
		var id = $("#table_list").jqGrid('getGridParam','selrow');
		if(id != null) {
			layerDialog("增加库存",'__URL__/addSub?id='+id,"90%","50%",true);
    	}else {
    		layer.msg("请先点击选择相应的仓库！");
    	}
	})
	
    //改（库存）
    $("#editSub").click(function() {
    	var id = $("#table_list2").jqGrid('getGridParam','selrow');
    	if(id != null) {
    		layerDialog("修改库存",'__URL__/editSub?id='+id,"90%","60%",true);
    	}else {
    		layer.msg("您没有选取数据！");
    	}
    })
    
});
</script>
</html>